package com.supcon.exchangedata.service.hj;


import com.supcon.exchangedata.pojo.entity.AjaxMessage;
import com.supcon.exchangedata.pojo.entity.mysql.operation.hj.HjCleanOrganized;
import com.supcon.exchangedata.pojo.entity.oracle.HjOrganized;
import com.supcon.exchangedata.repository.master.MasterHjOrganizedRepository;
import com.supcon.exchangedata.repository.slave6.SlaveHjCleanOrganizedInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Service
@Slf4j
public class HjCleanOrganizedService {
    @Autowired
    private SlaveHjCleanOrganizedInfo slaveHjCleanOrganizedInfo;
    @Autowired
    private MasterHjOrganizedRepository masterHjOrganizedRepository;

    public static String NAME1="水资源再生";
    public static String NAME2="厨余一期1";
    public static String NAME3="污水一厂";
    public static String NAME4="转运体项目";
    public static String NAME5="污水二厂";
    public static String NAME6="餐厨二期项目";
    public static String NAME7="厨余二期项目";
    public static String NAME8="厨余一期2";
    public static String NAME9="餐厨一期";

    public void synchronizationOrganized(){
        //实时数据同步到我们实时数据表
        //查询前置库数据  水资源再生
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        HjCleanOrganized hjCleanOrganized = slaveHjCleanOrganizedInfo.acquireRealTimeData(NAME1);
        if (null!=hjCleanOrganized){
            HjOrganized byId = masterHjOrganizedRepository.getById(sim.format(new Date()),NAME1);
            if (byId==null){
                HjOrganized hjOrganized = new HjOrganized();
                hjOrganized.setAddress(hjCleanOrganized.getAddress());
                hjOrganized.setBizTime(hjCleanOrganized.getBizTime());
                hjOrganized.setConcH2s(hjCleanOrganized.getConcH2s());
                hjOrganized.setConcH2sMg(hjCleanOrganized.getConcH2sMg());
                hjOrganized.setConcNh3(hjCleanOrganized.getConcNh3());
                hjOrganized.setConcNh3Mg(hjCleanOrganized.getConcNh3Mg());
                hjOrganized.setErH2s(hjCleanOrganized.getErH2s());
                hjOrganized.setErNh3(hjCleanOrganized.getErNh3());
                hjOrganized.setFv(hjCleanOrganized.getFv());
                hjOrganized.setDay(dateTimeFormatter.format(hjCleanOrganized.getBizTime()));
                hjOrganized.setId(hjCleanOrganized.getTongid()+"");
                masterHjOrganizedRepository.save(hjOrganized);
            }
        }
        //查询前置库 厨一期1
        HjCleanOrganized hjCleanOrganized1 = slaveHjCleanOrganizedInfo.acquireRealTimeData(NAME2);
        if (null!=hjCleanOrganized1){
            HjOrganized byId = masterHjOrganizedRepository.getById(sim.format(new Date()),NAME2);
            if (byId==null){
                HjOrganized hjOrganized = new HjOrganized();
                hjOrganized.setAddress(hjCleanOrganized1.getAddress());
                hjOrganized.setBizTime(hjCleanOrganized1.getBizTime());
                hjOrganized.setConcH2s(hjCleanOrganized1.getConcH2s());
                hjOrganized.setConcH2sMg(hjCleanOrganized1.getConcH2sMg());
                hjOrganized.setConcNh3(hjCleanOrganized1.getConcNh3());
                hjOrganized.setConcNh3Mg(hjCleanOrganized1.getConcNh3Mg());
                hjOrganized.setFv(hjCleanOrganized1.getFv());
                hjOrganized.setErH2s(hjCleanOrganized1.getErH2s());
                hjOrganized.setErNh3(hjCleanOrganized1.getErNh3());
                hjOrganized.setDay(dateTimeFormatter.format(hjCleanOrganized1.getBizTime()));
                hjOrganized.setId(hjCleanOrganized1.getTongid()+"");
                masterHjOrganizedRepository.save(hjOrganized);
            }
        }
        //查询前置库 污水一厂
        HjCleanOrganized hjCleanOrganized2 = slaveHjCleanOrganizedInfo.acquireRealTimeData(NAME3);
        if (null!=hjCleanOrganized2){
            HjOrganized byId = masterHjOrganizedRepository.getById(sim.format(new Date()),NAME3);
            if (byId==null){
                HjOrganized hjOrganized = new HjOrganized();
                hjOrganized.setAddress(hjCleanOrganized2.getAddress());
                hjOrganized.setBizTime(hjCleanOrganized2.getBizTime());
                hjOrganized.setConcH2s(hjCleanOrganized2.getConcH2s());
                hjOrganized.setConcH2sMg(hjCleanOrganized2.getConcH2sMg());
                hjOrganized.setConcNh3(hjCleanOrganized2.getConcNh3());
                hjOrganized.setConcNh3Mg(hjCleanOrganized2.getConcNh3Mg());
                hjOrganized.setFv(hjCleanOrganized2.getFv());
                hjOrganized.setErH2s(hjCleanOrganized2.getErH2s());
                hjOrganized.setErNh3(hjCleanOrganized2.getErNh3());
                hjOrganized.setDay(dateTimeFormatter.format(hjCleanOrganized2.getBizTime()));
                hjOrganized.setId(hjCleanOrganized2.getTongid()+"");
                masterHjOrganizedRepository.save(hjOrganized);
            }
        }
        //查询前置库  转运体项目
        HjCleanOrganized hjCleanOrganized3 = slaveHjCleanOrganizedInfo.acquireRealTimeData(NAME4);
        if (null!=hjCleanOrganized3){
            HjOrganized byId = masterHjOrganizedRepository.getById(sim.format(new Date()),NAME4);
            if (byId==null){
                HjOrganized hjOrganized = new HjOrganized();
                hjOrganized.setAddress(hjCleanOrganized3.getAddress());
                hjOrganized.setBizTime(hjCleanOrganized3.getBizTime());
                hjOrganized.setConcH2s(hjCleanOrganized3.getConcH2s());
                hjOrganized.setConcH2sMg(hjCleanOrganized3.getConcH2sMg());
                hjOrganized.setConcNh3(hjCleanOrganized3.getConcNh3());
                hjOrganized.setConcNh3Mg(hjCleanOrganized3.getConcNh3Mg());
                hjOrganized.setFv(hjCleanOrganized3.getFv());
                hjOrganized.setErH2s(hjCleanOrganized3.getErH2s());
                hjOrganized.setErNh3(hjCleanOrganized3.getErNh3());
                hjOrganized.setDay(dateTimeFormatter.format(hjCleanOrganized3.getBizTime()));
                hjOrganized.setId(hjCleanOrganized3.getTongid()+"");
                masterHjOrganizedRepository.save(hjOrganized);
            }
        }
        //查询前置库 餐厨二期项目
        HjCleanOrganized hjCleanOrganized4 = slaveHjCleanOrganizedInfo.acquireRealTimeData(NAME5);
        if (null!=hjCleanOrganized4){
            HjOrganized byId = masterHjOrganizedRepository.getById(sim.format(new Date()),NAME5);
            if (byId==null){
                HjOrganized hjOrganized = new HjOrganized();
                hjOrganized.setAddress(hjCleanOrganized4.getAddress());
                hjOrganized.setBizTime(hjCleanOrganized4.getBizTime());
                hjOrganized.setConcH2s(hjCleanOrganized4.getConcH2s());
                hjOrganized.setConcH2sMg(hjCleanOrganized4.getConcH2sMg());
                hjOrganized.setConcNh3(hjCleanOrganized4.getConcNh3());
                hjOrganized.setConcNh3Mg(hjCleanOrganized4.getConcNh3Mg());
                hjOrganized.setFv(hjCleanOrganized4.getFv());
                hjOrganized.setErH2s(hjCleanOrganized4.getErH2s());
                hjOrganized.setErNh3(hjCleanOrganized4.getErNh3());
                hjOrganized.setDay(dateTimeFormatter.format(hjCleanOrganized4.getBizTime()));
                hjOrganized.setId(hjCleanOrganized4.getTongid()+"");
                masterHjOrganizedRepository.save(hjOrganized);
            }
        }

        //查询前置库 污水二厂
        HjCleanOrganized hjCleanOrganized5 = slaveHjCleanOrganizedInfo.acquireRealTimeData(NAME6);
        if (null!=hjCleanOrganized5){
            HjOrganized byId = masterHjOrganizedRepository.getById(sim.format(new Date()),NAME6);
            if (byId==null){
                HjOrganized hjOrganized = new HjOrganized();
                hjOrganized.setAddress(hjCleanOrganized5.getAddress());
                hjOrganized.setBizTime(hjCleanOrganized5.getBizTime());
                hjOrganized.setConcH2s(hjCleanOrganized5.getConcH2s());
                hjOrganized.setConcH2sMg(hjCleanOrganized5.getConcH2sMg());
                hjOrganized.setConcNh3(hjCleanOrganized5.getConcNh3());
                hjOrganized.setConcNh3Mg(hjCleanOrganized5.getConcNh3Mg());
                hjOrganized.setFv(hjCleanOrganized5.getFv());
                hjOrganized.setErH2s(hjCleanOrganized5.getErH2s());
                hjOrganized.setErNh3(hjCleanOrganized5.getErNh3());
                hjOrganized.setDay(dateTimeFormatter.format(hjCleanOrganized5.getBizTime()));
                hjOrganized.setId(hjCleanOrganized5.getTongid()+"");
                masterHjOrganizedRepository.save(hjOrganized);
            }
        }

        //查询前置库 厨余二期项目
        HjCleanOrganized hjCleanOrganized6 = slaveHjCleanOrganizedInfo.acquireRealTimeData(NAME7);
        if (null!=hjCleanOrganized6){
            HjOrganized byId = masterHjOrganizedRepository.getById(sim.format(new Date()),NAME7);
            if (byId==null){
                HjOrganized hjOrganized = new HjOrganized();
                hjOrganized.setAddress(hjCleanOrganized6.getAddress());
                hjOrganized.setBizTime(hjCleanOrganized6.getBizTime());
                hjOrganized.setConcH2s(hjCleanOrganized6.getConcH2s());
                hjOrganized.setConcH2sMg(hjCleanOrganized6.getConcH2sMg());
                hjOrganized.setConcNh3(hjCleanOrganized6.getConcNh3());
                hjOrganized.setConcNh3Mg(hjCleanOrganized6.getConcNh3Mg());
                hjOrganized.setFv(hjCleanOrganized6.getFv());
                hjOrganized.setErH2s(hjCleanOrganized6.getErH2s());
                hjOrganized.setErNh3(hjCleanOrganized6.getErNh3());
                hjOrganized.setDay(dateTimeFormatter.format(hjCleanOrganized6.getBizTime()));
                hjOrganized.setId(hjCleanOrganized6.getTongid()+"");
                masterHjOrganizedRepository.save(hjOrganized);
            }
        }
        //查询前置库 餐厨一期
        HjCleanOrganized hjCleanOrganized8 = slaveHjCleanOrganizedInfo.acquireRealTimeData(NAME9);
        if (null!=hjCleanOrganized8){
            HjOrganized byId = masterHjOrganizedRepository.getById(sim.format(new Date()),NAME9);
            if (byId==null){
                HjOrganized hjOrganized = new HjOrganized();
                hjOrganized.setAddress(hjCleanOrganized8.getAddress());
                hjOrganized.setBizTime(hjCleanOrganized8.getBizTime());
                hjOrganized.setConcH2s(hjCleanOrganized8.getConcH2s());
                hjOrganized.setConcH2sMg(hjCleanOrganized8.getConcH2sMg());
                hjOrganized.setConcNh3(hjCleanOrganized8.getConcNh3());
                hjOrganized.setConcNh3Mg(hjCleanOrganized8.getConcNh3Mg());
                hjOrganized.setFv(hjCleanOrganized8.getFv());
                hjOrganized.setErH2s(hjCleanOrganized8.getErH2s());
                hjOrganized.setErNh3(hjCleanOrganized8.getErNh3());
                hjOrganized.setDay(dateTimeFormatter.format(hjCleanOrganized8.getBizTime()));
                hjOrganized.setId(hjCleanOrganized8.getTongid()+"");
                masterHjOrganizedRepository.save(hjOrganized);
            }
        }
    }
}
